import CryptoJS from 'crypto-js'

const Base64 = require('js-base64').Base64
// 密钥
const aeskey = CryptoJS.enc.Utf8.parse('KAasAeYzI35X49uR')
const aesiv = CryptoJS.enc.Utf8.parse('fm226In2iScu46th')

// 解密
export function decrypt(word) {
  word = Base64.decode(word)
  const decryptStr = CryptoJS.AES.decrypt(word, aeskey, {
    iv: aesiv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  return CryptoJS.enc.Utf8.stringify(decryptStr).toString()
}
// 加密
export function encrypt(word) {
  return CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(word), aeskey, {
    iv: aesiv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  }).toString()
}
